

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.nn.FakeQuantWithMinMaxObserver &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.nn.MulQuant" href="mindspore.nn.MulQuant.html" />
    <link rel="prev" title="mindspore.nn.DenseQuant" href="mindspore.nn.DenseQuant.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id1">基本构成单元</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id2">容器</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id3">卷积层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id4">梯度</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id5">循环层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id6">稀疏层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id7">非线性激活函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id8">工具</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id9">图像</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id10">归一化层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id11">池化层</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.nn.html#id12">量化</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.ActQuant.html">mindspore.nn.ActQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnAct.html">mindspore.nn.Conv2dBnAct</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnFoldQuant.html">mindspore.nn.Conv2dBnFoldQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnFoldQuantOneConv.html">mindspore.nn.Conv2dBnFoldQuantOneConv</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnWithoutFoldQuant.html">mindspore.nn.Conv2dBnWithoutFoldQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dQuant.html">mindspore.nn.Conv2dQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.DenseBnAct.html">mindspore.nn.DenseBnAct</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.DenseQuant.html">mindspore.nn.DenseQuant</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.nn.FakeQuantWithMinMaxObserver</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.MulQuant.html">mindspore.nn.MulQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.TensorAddQuant.html">mindspore.nn.TensorAddQuant</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id13">损失函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id14">优化器</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#wrapper">Wrapper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id15">数学运算</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id16">评估指标</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id17">动态学习率</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.nn.html">mindspore.nn</a> &raquo;</li>
        
      <li>mindspore.nn.FakeQuantWithMinMaxObserver</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/nn/mindspore.nn.FakeQuantWithMinMaxObserver.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-nn-fakequantwithminmaxobserver">
<h1>mindspore.nn.FakeQuantWithMinMaxObserver<a class="headerlink" href="#mindspore-nn-fakequantwithminmaxobserver" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.nn.FakeQuantWithMinMaxObserver">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.nn.</code><code class="sig-name descname">FakeQuantWithMinMaxObserver</code><span class="sig-paren">(</span><em class="sig-param">min_init=-6</em>, <em class="sig-param">max_init=6</em>, <em class="sig-param">ema=False</em>, <em class="sig-param">ema_decay=0.999</em>, <em class="sig-param">per_channel=False</em>, <em class="sig-param">channel_axis=1</em>, <em class="sig-param">num_channels=1</em>, <em class="sig-param">quant_dtype=QuantDtype.INT8</em>, <em class="sig-param">symmetric=False</em>, <em class="sig-param">narrow_range=False</em>, <em class="sig-param">quant_delay=0</em>, <em class="sig-param">neg_trunc=False</em>, <em class="sig-param">mode=&quot;DEFAULT&quot;</em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/mindspore/nn/layer/quant.html#FakeQuantWithMinMaxObserver"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mindspore.nn.FakeQuantWithMinMaxObserver" title="Permalink to this definition">¶</a></dt>
<dd><p>Quantization aware operation which provides the fake quantization observer function on data with min and max.</p>
<p>The detail of the quantization mode <cite>DEFAULT</cite> is described as below:</p>
<p>The running min/max <span class="math notranslate nohighlight">\(x_{min}\)</span> and <span class="math notranslate nohighlight">\(x_{max}\)</span> are computed as:</p>
<div class="math notranslate nohighlight">
\[\begin{split}\begin{array}{ll} \\
    x_{min} =
    \begin{cases}
        \min(\min(X), 0)
          &amp; \text{ if } ema = \text{False} \\
        \min((1 - c) \min(X) + \text{c } x_{min}, 0)
          &amp; \text{ if } \text{otherwise}
    \end{cases}\\
    x_{max} =
    \begin{cases}
        \max(\max(X), 0)
          &amp; \text{ if } ema = \text{False} \\
        \max((1 - c) \max(X) + \text{c } x_{max}, 0)
          &amp; \text{ if } \text{otherwise}
    \end{cases}
\end{array}\end{split}\]</div>
<p>where X is the input tensor, and <span class="math notranslate nohighlight">\(c\)</span> is the <cite>ema_decay</cite>.</p>
<p>The scale and zero point zp is computed as:</p>
<div class="math notranslate nohighlight">
\[\begin{split}\begin{array}{ll} \\
    scale =
    \begin{cases}
        \frac{x_{max} - x_{min}}{Q_{max} - Q_{min}}
          &amp; \text{ if } symmetric = \text{False} \\
        \frac{2\max(x_{max}, \left | x_{min} \right |) }{Q_{max} - Q_{min}}
          &amp; \text{ if } \text{otherwise}
    \end{cases}\\
    zp\_min = Q_{min} - \frac{x_{min}}{scale} \\
    zp = \left \lfloor \min(Q_{max}, \max(Q_{min}, zp\_min)) + 0.5 \right \rfloor
\end{array}\end{split}\]</div>
<p>where <span class="math notranslate nohighlight">\(Q_{max}\)</span> and <span class="math notranslate nohighlight">\(Q_{min}\)</span> is decided by quant_dtype, for example, if quant_dtype=INT8,
then <span class="math notranslate nohighlight">\(Q_{max} = 127\)</span> and <span class="math notranslate nohighlight">\(Q_{min} = -128\)</span>.</p>
<p>The fake quant output is computed as:</p>
<div class="math notranslate nohighlight">
\[\begin{split}\begin{array}{ll} \\
    u_{min} = (Q_{min} - zp) * scale \\
    u_{max} = (Q_{max} - zp) * scale \\
    u_X = \left \lfloor \frac{\min(u_{max}, \max(u_{min}, X)) - u_{min}}{scale}
    + 0.5 \right \rfloor \\
    output = u_X * scale + u_{min}
\end{array}\end{split}\]</div>
<p>The detail of the quantization mode <cite>LEARNED_SCALE</cite> is described as below:</p>
<p>The fake quant output is computed as:</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\begin{split}\bar{X}=\left\{\begin{matrix}
clip\left ( \frac{X}{maxq},0,1\right ) \qquad \quad if\quad neg\_trunc\\
clip\left ( \frac{X}{maxq},-1,1\right )\qquad \ if\quad otherwise
\end{matrix}\right. \\\end{split}\\output=\frac{floor\left ( \bar{X}\ast  Q_{max}+0.5  \right ) \ast scale }{Q_{max}}\end{aligned}\end{align} \]</div>
<p>where X is the input tensor.
where <span class="math notranslate nohighlight">\(Q_{max}\)</span> (quant_max) is decided by quant_dtype and neg_trunc, for example, if quant_dtype=INT8
and neg_trunc works, <span class="math notranslate nohighlight">\(Q_{max} = 256\)</span> , otherwise <span class="math notranslate nohighlight">\(Q_{max} = 127\)</span>.</p>
<p>The maxq is updated by training, and its gradient is calculated as follows:</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\begin{split}\frac{\partial \ output}{\partial \ maxq} = \left\{\begin{matrix}
-\frac{X}{maxq}+\left \lfloor \frac{X}{maxq} \right \rceil \qquad if\quad bound_{lower}&lt; \frac{X}{maxq}&lt; 1\\
-1 \qquad \quad \qquad \quad if\quad \frac{X}{maxq}\le bound_{lower}\\
 1  \qquad \quad \qquad \quad if\quad \frac{X}{maxq}\ge  1 \qquad \quad
\end{matrix}\right. \\\end{split}\\\begin{split}bound_{lower}=
\left\{\begin{matrix}
 0\qquad \quad if\quad neg\_trunc\\
-1\qquad if\quad otherwise
\end{matrix}\right.\end{split}\end{aligned}\end{align} \]</div>
<p>Then minq is computed as:</p>
<div class="math notranslate nohighlight">
\[\begin{split}minq=\left\{\begin{matrix}
0  \qquad \qquad \quad if\quad neg\_trunc\\
-maxq\qquad if\quad otherwise
\end{matrix}\right.\end{split}\]</div>
<p>When exporting, the scale and zero point zp is computed as:</p>
<div class="math notranslate nohighlight">
\[\begin{split}scale=\frac{maxq}{quant\_max} ,\quad zp=0 \\\end{split}\]</div>
<p>zp is equal to 0 consistently, due to the LEARNED_SCALE`s symmetric nature.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>min_init</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#int" title="(in Python v3.8)"><em>int</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/functions.html#float" title="(in Python v3.8)"><em>float</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/stdtypes.html#list" title="(in Python v3.8)"><em>list</em></a>) – The initialized min value. Default: -6.</p></li>
<li><p><strong>max_init</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#int" title="(in Python v3.8)"><em>int</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/functions.html#float" title="(in Python v3.8)"><em>float</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/stdtypes.html#list" title="(in Python v3.8)"><em>list</em></a>) – The initialized max value. Default: 6.</p></li>
<li><p><strong>ema</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#bool" title="(in Python v3.8)"><em>bool</em></a>) – The exponential Moving Average algorithm updates min and max. Default: False.</p></li>
<li><p><strong>ema_decay</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#float" title="(in Python v3.8)"><em>float</em></a>) – Exponential Moving Average algorithm parameter. Default: 0.999.</p></li>
<li><p><strong>per_channel</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#bool" title="(in Python v3.8)"><em>bool</em></a>) – Quantization granularity based on layer or on channel. Default: False.</p></li>
<li><p><strong>channel_axis</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#int" title="(in Python v3.8)"><em>int</em></a>) – Quantization by channel axis. Default: 1.</p></li>
<li><p><strong>num_channels</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#int" title="(in Python v3.8)"><em>int</em></a>) – declarate the min and max channel size, Default: 1.</p></li>
<li><p><strong>quant_dtype</strong> (<a class="reference internal" href="../mindspore.compression.html#mindspore.compression.common.QuantDtype" title="mindspore.compression.common.QuantDtype"><em>QuantDtype</em></a>) – The datatype of quantization, supporting 4 and 8bits. Default: QuantDtype.INT8.</p></li>
<li><p><strong>symmetric</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#bool" title="(in Python v3.8)"><em>bool</em></a>) – Whether the quantization algorithm is symmetric or not. Default: False.</p></li>
<li><p><strong>narrow_range</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#bool" title="(in Python v3.8)"><em>bool</em></a>) – Whether the quantization algorithm uses narrow range or not. Default: False.</p></li>
<li><p><strong>quant_delay</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#int" title="(in Python v3.8)"><em>int</em></a>) – Quantization delay parameters according to the global step. Default: 0.</p></li>
<li><p><strong>neg_trunc</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#bool" title="(in Python v3.8)"><em>bool</em></a>) – Whether the quantization algorithm uses negative truncation or not. Default: False.</p></li>
<li><p><strong>mode</strong> (<a class="reference external" href="https://docs.python.org/library/stdtypes.html#str" title="(in Python v3.8)"><em>str</em></a>) – Optional quantization mode, currently only <cite>DEFAULT`(QAT) and `LEARNED_SCALE</cite> are supported.
Default: (“DEFAULT”)</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Inputs:</dt><dd><ul class="simple">
<li><p><strong>x</strong> (Tensor) - The input of FakeQuantWithMinMaxObserver. The input dimension is preferably 2D or 4D.</p></li>
</ul>
</dd>
<dt>Outputs:</dt><dd><p>Tensor, with the same type and shape as the <cite>x</cite>.</p>
</dd>
</dl>
<dl class="field-list simple">
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><ul class="simple">
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#TypeError" title="(in Python v3.8)"><strong>TypeError</strong></a> – If <cite>min_init</cite> or <cite>max_init</cite> is not int, float or list.</p></li>
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#TypeError" title="(in Python v3.8)"><strong>TypeError</strong></a> – If <cite>quant_delay</cite> is not an int.</p></li>
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#ValueError" title="(in Python v3.8)"><strong>ValueError</strong></a> – If <cite>quant_delay</cite> is less than 0.</p></li>
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#ValueError" title="(in Python v3.8)"><strong>ValueError</strong></a> – If <cite>min_init</cite> is not less than <cite>max_init</cite>.</p></li>
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#ValueError" title="(in Python v3.8)"><strong>ValueError</strong></a> – If <cite>mode</cite> is neither <cite>DEFAULT</cite> nor <cite>LEARNED_SCALE</cite>.</p></li>
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#ValueError" title="(in Python v3.8)"><strong>ValueError</strong></a> – If <cite>mode</cite> is <cite>LEARNED_SCALE</cite> and <cite>symmetric</cite> is not <cite>True</cite>.</p></li>
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#ValueError" title="(in Python v3.8)"><strong>ValueError</strong></a> – If <cite>mode</cite> is <cite>LEARNED_SCALE</cite>, and <cite>narrow_range</cite> is not <cite>True</cite> unless when <cite>neg_trunc</cite> is <cite>True</cite>.</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Supported Platforms:</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Ascend</span></code> <code class="docutils literal notranslate"><span class="pre">GPU</span></code></p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">mindspore</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">Tensor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fake_quant</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">FakeQuantWithMinMaxObserver</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Tensor</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]]),</span> <span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">fake_quant</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="go">[[ 0.9882355  1.9764705  0.9882355]</span>
<span class="go"> [-1.9764705  0.        -0.9882355]]</span>
</pre></div>
</div>
<dl class="method">
<dt id="mindspore.nn.FakeQuantWithMinMaxObserver.extend_repr">
<code class="sig-name descname">extend_repr</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/mindspore/nn/layer/quant.html#FakeQuantWithMinMaxObserver.extend_repr"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mindspore.nn.FakeQuantWithMinMaxObserver.extend_repr" title="Permalink to this definition">¶</a></dt>
<dd><p>Display instance object as string.</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.nn.FakeQuantWithMinMaxObserver.reset">
<code class="sig-name descname">reset</code><span class="sig-paren">(</span><em class="sig-param">quant_dtype=QuantDtype.INT8</em>, <em class="sig-param">min_init=-6</em>, <em class="sig-param">max_init=6</em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/mindspore/nn/layer/quant.html#FakeQuantWithMinMaxObserver.reset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mindspore.nn.FakeQuantWithMinMaxObserver.reset" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset the quant max parameter (eg. 256) and the initial value of the minq parameter and maxq parameter,
this function is currently only valid for <cite>LEARNED_SCALE</cite> mode.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>quant_dtype</strong> (<a class="reference internal" href="../mindspore.compression.html#mindspore.compression.common.QuantDtype" title="mindspore.compression.common.QuantDtype"><em>QuantDtype</em></a>) – The datatype of quantization, supporting 4 and 8bits. Default: QuantDtype.INT8.</p></li>
<li><p><strong>min_init</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#int" title="(in Python v3.8)"><em>int</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/functions.html#float" title="(in Python v3.8)"><em>float</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/stdtypes.html#list" title="(in Python v3.8)"><em>list</em></a>) – The initialized min value. Default: -6.</p></li>
<li><p><strong>max_init</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#int" title="(in Python v3.8)"><em>int</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/functions.html#float" title="(in Python v3.8)"><em>float</em></a><em>, </em><a class="reference external" href="https://docs.python.org/library/stdtypes.html#list" title="(in Python v3.8)"><em>list</em></a>) – The initialized max value. Default: 6.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.nn.MulQuant.html" class="btn btn-neutral float-right" title="mindspore.nn.MulQuant" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.nn.DenseQuant.html" class="btn btn-neutral float-left" title="mindspore.nn.DenseQuant" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>